// 创建返回顶部按钮
(function createGoback(){
    var body = document.querySelector("body");
    var goback = document.createElement("div");
    var img = document.createElement("img");
    goback.className="goback";
    img.src = "../images/回到顶部.png";
    goback.appendChild(img);
    body.appendChild(goback);
    scrollBack(goback);
})()

//返回顶部
function scrollBack(goback){
    window.addEventListener("scroll",function(){
        goBackBtn(goback);
    })
    goback.addEventListener("click",function(){
        // 丝滑地滚回顶部
        window.scrollTo({
            top: 0,
            behavior: "smooth",
        });
    })
} 
// 显示返回顶部按钮
function goBackBtn(goback){
    if(window.pageYOffset >= 200){
        goback.style.display = "block";
    }else{
        goback.style.display = "none";
    }
}
